<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改用车申请')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-use-edit" th:object="${tmdCarUse}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label">编号：</label>
                <div class="col-sm-8">
                    <input name="id" th:field="*{id}"class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">申请名称：</label>
                <div class="col-sm-8">
                    <input name="context" th:field="*{context}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">创建人：</label>
                <div class="col-sm-8">
                    <input name="createPeople" th:field="*{createPeople}" class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">创建时间：</label>
                <div class="col-sm-8">
                    <input name="createTime" th:value="${#dates.format(tmdCarUse.createTime, 'yyyy-MM-dd HH:mm:ss')}" class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">紧急程度：</label>
                <div class="col-sm-8">
                    <select class="form-control m-b" name="level"
                            th:with="type=${@dict.getType('level')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                th:value="${dict.dictValue}">

                        </option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">部门：</label>
                <div class="col-sm-8">
                    <select id="departmentSelect" class="form-control" name="deptId">
                        <option value="">请选择部门</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">车牌号：</label>
                <div class="col-sm-8">
                    <input name="carCard" th:field="*{carList.carCard}" class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">车辆名称：</label>
                <div class="col-sm-8">
                    <input name="carName" th:field="*{carList.carName}" class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">开始时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="startTime" th:value="${#dates.format(tmdCarUse.startTime, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">结束时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="endTime" th:value="${#dates.format(tmdCarUse.endTime, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">始发地：</label>
                <div class="col-sm-8">
                    <input name="startPlace" th:field="*{startPlace}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">目的地：</label>
                <div class="col-sm-8">
                    <input name="destPlace" th:field="*{destPlace}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">司机：</label>
                <div class="col-sm-8">
                    <input name="userName" th:field="*{sysUser.userName}" class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">司机电话：</label>
                <div class="col-sm-8">
                    <input name="phonenumber" th:field="*{sysUser.phonenumber}" class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">用车事由：</label>
                <div class="col-sm-8">
                    <textarea name="reason" class="form-control">[[*{reason}]]</textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">附件：</label>
                <div class="col-sm-8">
                    <input type="hidden" name="file" th:field="*{file}">
                    <div class="file-loading">
                        <input class="form-control file-upload" id="file" name="file" type="file">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="notes" class="form-control">[[*{notes}]]</textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <script th:inline="javascript">


        var carStatusDatas = [[${@dict.getType('category_status')}]];
        var prefix = ctx + "car/use";
        $("#form-use-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-use-edit').serialize());
            }
        }

        $("input[name='startTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='endTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $(".file-upload").each(function (i) {
            var val = $("input[name='" + this.id + "']").val()
            $(this).fileinput({
                'uploadUrl': ctx + 'common/upload',
                initialPreviewAsData: true,
                initialPreview: [val],
                maxFileCount: 1,
                autoReplace: true
            }).on('fileuploaded', function (event, data, previewId, index) {
                $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })
            $(this).fileinput('_initFileActions');
        });


        $(document).ready(function () {
            $.ajax({
                url: ctx + "car/manage" + '/getDepartments',
                type: 'GET',
                dataType: 'json',
                success: function (response) {
                    var departments = response.data;
                    var selectElement = $('#departmentSelect');
                    $.each(departments, function (index, department) {
                        selectElement.append($('<option>', {
                            value: department.deptId,
                            text: department.deptName
                        }));
                    });
                },
                error: function (xhr, status, error) {
                    console.error('错误', error);
                }
            });
        });
    </script>
</body>
</html>